package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperator;
import org.springframework.beans.ExtendedBeanInfoFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception{
        String originalFilename = file.getOriginalFilename();
//        String uuid = UUID.randomUUID().toString();
//        String extName = originalFilename.substring(originalFilename.lastIndexOf(","));
//        String newFileName = uuid + extName;
//        file.transferTo(new File("D:\\heima21\\"+newFileName));
        String url = aliyunOSSOperator.upload(file.getBytes(),originalFilename);
        return Result.success(url);
    }
}
